﻿/**
 * Title:CKEditor插件示范 Author:耿明(http://www.mzone.cc) Date:2014-10-10
 */

function fujianUpload(){
	$("#cb_fujian_thumb").ajaxStart(function(){
		$("#cb_fujian_thumb").html('上传中');
 	});

	$.ajaxFileUpload({
		url:ctx+'/file/ftpupload.html',
		secureuri:false,
		fileElementId:'cb_fujian',
		dataType: 'json',
		success: function (data, status){	
			$("#cb_fujian_thumb").empty();
		
			if(data.status==true || data.status=="true") {
				$("#cb_fujian_path").val(data.data.filepath);
				$("#cb_fujian_filename").val(data.data.filename);
			} else {
				alert(data.msg);
				$("#cb_fujian_thumb").html(data.msg);
			}
		},
		error: function (data, status, e){
			alert("上传失败，请重新尝试。");
		}
	});
}

CKEDITOR.dialog.add('annex', function(editor){
    var escape = function(value){
        return value;
    };
    
    return {
        title: '附件控件',
        resizable: CKEDITOR.DIALOG_RESIZE_BOTH,
        minWidth: 300,
        minHeight: 300,
        contents: [{
            id: 'cb',
            name: 'cb',
            label: 'cb',
            title: 'cb',
            elements: [{
                type:'html',
                html:'<h3>上传附件</h3>'+
                	 '<p id="cb_fujian_thumb" style="color:red;"></p>'+
                	 '<input type="file" name="cmfile" id="cb_fujian" onchange="fujianUpload()" /><input type="hidden" id="cb_fujian_path" /><input type="hidden" id="cb_fujian_filename" /><br/>'+
                	 '<span>说明：选择的附件生成链接。</span>'
            }]
        }],
        onOk: function(){
            var fujian = $("#cb_fujian_filename").val();
			var path = $("#cb_fujian_path").val();
			if(path!="") {
				editor.insertHtml("<a target = '_blank' href="+ftp_url+path+">" + fujian + "</a>");
			}
        }
    };
});